import axios from '@/utils/request/axios';

export class GetShipListParams {
  page: number;
  length: number;
}

export class ShipItem {
  id: number;
  mmsi: string;
  shipName: string;
  shipType: string;
  lengthM: number;
  beamM: number;
  heightM: number;
  comment: string;
}

export async function getShipList(params: GetShipListParams) {
  const res = await axios({
    method: 'get',
    url: `/vessel/list`,
    params,
  });
  return {
    list: res.data.data.list as ShipItem[],
    total: res.data.data.total || 0,
  };
}

export class EditShipData {
  /** 船号 */
  mmsi: string;
  /** 名称 */
  shipName: string;
  /** 类型 */
  shipType: string;
  /** 长 */
  lengthM: number;
  /** 宽 */
  beamM: number;
  /** 高 */
  heightM: number;
  /** 备注 */
  comment: string;
}

export async function addShip(data: EditShipData) {
  const res = await axios({
    method: 'post',
    url: '/vessel/save',
    data,
  });
  return res.data;
}

export async function editShip(id: number, data: EditShipData) {
  const res = await axios({
    method: 'put',
    url: `/vessel/edit/${id}`,
    data,
  });
  return res.data;
}

export class DeleteShipData {
  /** 可批量，逗号分割 */
  ids: string;
}

export async function deleteShip(data: DeleteShipData) {
  const res = await axios({
    method: 'post',
    url: '/vessel/delete',
    data,
  });
  return res.data;
}
